package com.yaser.alfresco;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.yaser.alfresco.model.AlfrescoFolder;
import com.yaser.alfresco.model.FileList;

public class AlfrecoTest {

	/**
	 * @param args
	 */
	static String BASE_URL ="http://localhost:8080";
	
	public static void main(String[] args) {
		AlfrescoWebScripts cw = new AlfrescoWebScripts();
		
		Client c = Client.create();
		
		
		WebResource r2 = c.resource(BASE_URL+"/alfresco/service/api/login?u=admin&pw=admin");
		
		String responseLogin = r2.accept(MediaType.APPLICATION_XML).get(String.class);
		
		responseLogin = responseLogin.substring(responseLogin.indexOf("<ticket>")+8, responseLogin.indexOf("</ticket>"));
		
//		List<FileList> listChildrens = cw.listChildrens(responseLogin, "33674dac-9d29-48f9-aa69-ae734aa42102");
		
		
		
//		AlfrescoFolder f =cw.createFolder(responseLogin,BASE_URL,"a082f10c-5dab-4438-9ae7-3d3905a50e2d", "test",c);
//		
//		System.out.println("new folder created with the id : "+f.getFolderId());
//		
//		List<FileList> l =cw.listChildrens(responseLogin,BASE_URL,"659785d1-6e85-4d87-95d2-93aadb374140",c);
//		
//		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
//			FileList fileList = (FileList) iterator.next();
//			
//			System.out.println("Child :"+fileList.getChild());
//			System.out.println("Child Type:"+fileList.getChildType()+"\n");
//		}
		
//		String res=null;
//		
//		File f = new File("/home/yasaryasa/Masaüstü/lisansVerme.jpg");
//		String string = cw.fileUpload(responseLogin, "7005d78d-b190-4c73-b1cb-78249e9c53e5", f);
//		System.out.println("Response = "+res);
		
		
		List<FileList> name = cw.searchFilesByName("7005d78d-b190-4c73-b1cb-78249e9c53e5", "dene", responseLogin);
		System.out.println("Size = "+name.size());
		
//		AlfrescoFolder afolder = cw.createFolder(responseLogin, "localhost", "8080", "", "homeDeneme", c);
//		
//		System.out.println("Folder Id : " + afolder.getFolderId());
		
		
		
	}
}
